<?php


namespace app\api\controller;


use app\common\lib\Arr;
use app\common\lib\Show;

class Category extends ApiBase
{

    public function index()
    {
        // 获取所有分类的内容
        $categoryBusObj = new \app\common\business\Category();
        $categorys = $categoryBusObj->getNormalAllCategorys();
        //无限级分类
        $result = Arr::getTree($categorys);
        //无限级分类截取
        $result = Arr::sliceTreeArr($result);

        return Show::success($result);

    }


    //商品列表页 按栏目检索的内容
    public function search()
    {
        //接收 id数据
        $cid = input('cid', 0, "intval");

        //获取分类
        $result = (new \app\common\business\Category())->search($cid);

        if (!$result) {
            return [];
        }

        return Show::success($result);


    }


    //根据二级分类 获取三级分类数据
    public function sub()
    {
        $id = input('id', 0, "intval");


        //获取分类
        $result = (new \app\common\business\Category())->sub($id);
        if (!$result) {
            return [];
        }


        return Show::success($result);


    }
}